package ${package.Controller};

import com.rxw.nutmall.page.PageData;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.rxw.nutmall.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

<#if restControllerStyle>
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
@AllArgsConstructor
@Api(tags = "${table.comment!}")
public class ${table.controllerName} {
</#if>
    private ${table.serviceName} ${table.entityPath}Service;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageData<${entity}>> findPage(@RequestParam Map<String, Object> params) {
        PageData<${entity}> page = ${table.entityPath}Service.page(params);
        return new Result<PageData<${entity}>>().ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询")
    public Result<${entity}> get(@PathVariable("id") Long id) {
        ${entity} data = ${table.entityPath}Service.get(id);
        return new Result<${entity}>().ok(data);
    }

    @GetMapping("/getList")
    @ApiOperation("批量查询")
    public Result<List<${entity}>> getList(@RequestBody ${entity} dto) {
        List<${entity}> data = ${table.entityPath}Service.getList(dto);
        return new Result<List<${entity}>>().ok(data);
    }

    @PostMapping("/save")
    @ApiOperation("报存")
    public Result<Object> save(@RequestBody ${entity} dto) {
        String id = ${table.entityPath}Service.save(dto);
        return new Result<>().ok(id);
    }

    @PostMapping("/saveList")
    @ApiOperation("批量报存")
    public Result<Object> saveList(@RequestBody List<${entity}> list) {
        ${table.entityPath}Service.saveList(list);
        return new Result<>();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public Result<Object> delete(@PathVariable Long id) {
        ${table.entityPath}Service.remove(id);
        return new Result<>();
    }

    @DeleteMapping("/delete/batch")
    @ApiOperation("批量删除")
    public Result<Object> deleteList(@RequestBody List<Long> idList) {
        ${table.entityPath}Service.removeList(idList);
        return new Result<>();
    }

    @PutMapping("/update")
    @ApiOperation("修改")
    public Result<Object> update(@RequestBody ${entity} dto) {
        ${table.entityPath}Service.update(dto);
        return new Result<>();
    }

    @PutMapping("/update/batch")
    @ApiOperation("批量修改")
    public Result<Object> updateList(@RequestBody List<${entity}> list) {
        ${table.entityPath}Service.updateList(list);
        return new Result<>();
    }
}
</#if>
